﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Entity;
using DAL;

namespace Winform
{
    public partial class Form_Keyword_Operate : Form
    {
        public Form_Keyword_Operate()
        {
            InitializeComponent();
        }
        public Form_Keyword_Operate(Keyword key)
        {
            InitializeComponent();
            this.Text = "编辑任务";
            txtName.Text = key.Name;
            if (key.Page_From < 1)
            {
                key.Page_From = 1;
            }
            if (key.Page_To < 1)
            {
                key.Page_To = 1;
            }
            numFrom.Value = key.Page_From;
            numTo.Value = key.Page_To;
            _isIns = false;
            _Keyword = key;
            _oldKey = key.Name;
        }
        bool _isIns = true;
        Keyword _Keyword;
        string _oldKey;
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_isIns)
            {
                Keyword k = new Keyword();
                k.Name = txtName.Text.Trim();
                k.Page_From = Convert.ToInt32(numFrom.Value);
                k.Page_To = Convert.ToInt32(numTo.Value);
                DAL_Service.Keyword_Add(k);
                this.Close();
            }
            else
            {
                _Keyword.Name = txtName.Text.Trim();
                _Keyword.Page_From = Convert.ToInt32(numFrom.Value);
                _Keyword.Page_To = Convert.ToInt32(numTo.Value);
                DAL_Service.Keyword_Update(_Keyword, _oldKey);
                this.Close();
            }
        }
    }
}
